//
//  NSString+EV.h
//  EVClub
//
//  Created by sam on 14-8-29.
//  Copyright (c) 2014年 BitRice. All rights reserved.
//

#import <Foundation/Foundation.h>
@interface NSString (EV)

@property (nonatomic, copy, readonly) NSString *ev_MD5;

-(int)ev_wordsCount;

+ (NSString *)ev_encodeURIComponent:(NSString *)str;

- (NSString*)ev_URLEncoding;

- (NSString*)ev_URLDecodedString;

-(NSString*)ev_trim;

-(CGFloat)ev_toFloat;

-(NSString *)ev_unicode;

-(NSString *)ev_stringByRemovingExtraEmptyChar;

-(BOOL)ev_isNotEmptyString;

- (NSString *)ev_stringByRemoveSuffix:(NSString *)suffix;

/**
 *  比较两个以某个分隔符隔开元素的字符串，是否含有相同元素
 *  使用：[@"1,3,8" intersectsElement("1,2,4,7,9", ",")]; //YES
 */
-(BOOL)ev_intersectsElementString:(NSString *)otherString bySeparator:(NSString *)separator;
-(BOOL)ev_isEqualToElementString:(NSString *)otherString bySeparator:(NSString *)separator;
-(BOOL)ev_isSubOfElementString:(NSString *)otherString bySeparator:(NSString *)separator;

/**
 *  返回一个头部带图片的 attributeStr
 *
 *  @param imageName  图片名称
 *  @param rect       图片的位置 CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
 *  @param contentStr 后面的内容
 *
 *  @return 带图片的attributeStr
 */
+ (NSMutableAttributedString *)ev_attributeStrWithHeaderImage:(NSString *)imageName withBounds:(CGRect)rect withString:(NSString *)contentStr;
+ (NSMutableAttributedString *)ev_attributeStrWithImage:(UIImage *)img withBounds:(CGRect)rect withString:(NSString *)contentStr;
/**
 Match the regular expression, and executes a given block using each object in the matches.
 
 @param regex    The regular expression
 @param options  The matching options to report.
 @param block    The block to apply to elements in the array of matches.
 The block takes four arguments:
 match: The match substring.
 matchRange: The matching options.
 stop: A reference to a Boolean value. The block can set the value
 to YES to stop further processing of the array. The stop
 argument is an out-only argument. You should only ever set
 this Boolean to YES within the Block.
 */
- (void)ev_enumerateRegexMatches:(NSString *)regex
                      options:(NSRegularExpressionOptions)options
                   usingBlock:(void (^)(NSString *match, NSRange matchRange, BOOL *stop))block;

- (NSString *)ev_stringByMatching:(NSString *)regex capture:(NSInteger)capture;

@end

@interface NSString (EVTagDecoding)

- (NSArray *)ev_tagArray;

@end

@interface NSString (EVAdministrative)

+ (NSString *)ev_administrativeStringWithProvince:(NSString *)province city:(NSString *)city district:(NSString *)district splitString:(NSString *)splitString;

@end

@interface NSNull(EVString)
//覆盖系统方法，防止NSNull引起的崩溃
-(void)forwardInvocation:(NSInvocation *)anInvocation;
- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector;

@end

@interface NSNumber(EVString)
//覆盖系统方法，防止NSNull引起的崩溃
-(void)forwardInvocation:(NSInvocation *)anInvocation;
- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector;

@end

@interface NSString(hmacmd5)

/**
 * 返回hmacmd5加密字符串
 
 @param key 密钥
 @return 字符串表示形式
 */
- (NSString *)ev_hmacMD5StringWithKey:(NSString *)key;

/**
 返回二进制 Bytes 流的字符串表示形式
 
 @param bytes  二进制 Bytes 数组
 @param length 数组长度
 @return 字符串表示形式
 */
- (NSString *)ev_stringFromBytes:(unsigned char *)bytes length:(int)length;

@end
